#ifndef CNATIVEWIDGET_H
#define CNATIVEWIDGET_H

#include <QDebug>
#include <QWidget>

class CNativeHandler;

// Cross-platform frameless widget
// C means "custom" not MFC
class CNativeWidget : public QWidget {
    Q_OBJECT

    Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderChanged)
    Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth NOTIFY borderChanged)
    Q_PROPERTY(
        QMargins resizeMargins READ resizeMargins WRITE setResizeMargins NOTIFY borderChanged)
public:
    explicit CNativeWidget(QWidget *parent = nullptr);
    ~CNativeWidget();

public:
    void centralize(double r = 0);
    void maximize();
    void minimize();
    void normalize();
    void fullScreen();
    void showForward();

    bool resizable() const;
    void setResizable(bool resizable);

    QMargins resizeMargins() const;
    void setResizeMargins(const QMargins &margins);
    void setResizeMargins(int margin);

    int borderWidth() const;
    void setBorderWidth(int width);

    QColor borderColor() const;
    void setBorderColor(const QColor &borderColor);

private:
    void handleHandlerTestMouse(bool *result, bool set);
    void handleHandlerTestNative(bool *result, bool set);

protected:
    CNativeHandler *m_handler;
    bool m_handlerConstruct; // Avoid QEvent::ChildAdded Event

    virtual bool isMouseOnCaption() const;
    virtual bool isNative() const;

    virtual void setNative(bool native);

    bool event(QEvent *event) override;
    bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;

signals:
    void borderChanged();
};

#endif // CNATIVEWIDGET_H
